# makefile for Railgun boot setup
# device and partition number (change if necessary)
DEVICE=/dev/sda
PARTITION=/dev/sda1

# other variables
MBRC=mbrc/mbrc

# build mbrc tool
mbrc: 	mbrc/MBRMaker.c
	gcc mbrc/MBRMaker.c -o mbrc/mbrc -std=c99
	
# build mbr
mbr:	MBR.asm
	nasm MBR.asm -o MBR.bin

# build ext2 bootsector
ext2:	EXT2.asm
	nasm EXT2.asm -o EXT2.bin	

# copy to disk (see targers above)
disk:	EXT2.bin MBR.bin
	sudo $(MBRC) -f=MBR.bin -d=$(DEVICE)
	sleep 1
	sudo dd if=EXT2.bin of=$(PARTITION)
	sleep 1
	sync
	
# test
run:
	sudo qemu-system-x86_64 -drive file=$(DEVICE),if=ide,media=disk,index=0 -m 1024 -smp 2 -k en-us #-cpu qemu64,+x2apic

# build all
all:	mbr ext2 disk run
